#include <QApplication>
#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include "WriteLog.h"

const QString WriteLog::namefile = "log.txt";

WriteLog::WriteLog()
{

}

WriteLog::~WriteLog()
{

}

void WriteLog::writeToLog(QString message, QString title, QString fileNameWithError/* ="System" */)
{
	QString path = QApplication::applicationDirPath();
	QFile file(path + "/" + namefile);
	if(!file.open(QIODevice::Append))
		return;

	QTextStream stream(&file);
	QString writeFile;
	QString dateTime = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss");
	writeFile = "[";
	writeFile.append(fileNameWithError);
	writeFile.append("]\n");
	
	QString time = "["; 
	time.append(dateTime);
	time.append("]\t");
	title.append("\n");
	message.append("\n\n");
	stream << writeFile;
	stream << time;
	stream << title;
	stream << message;

	file.close();
}